<template>
  <div style="padding:15px">
    <vxe-toolbar id="toolbarId" :setting="{storage: true}" export :refresh="{query: findList}">
      <template v-slot:buttons>
        <el-button @click="findList">查询</el-button>
      </template>
    </vxe-toolbar>
    <vxe-table
      ref="xTable"
      border
      show-footer
      resizable
      stripe
      highlight-current-row
      highlight-hover-row
      show-header-overflow
      show-overflow
      row-id="id"
      class="mytable-footer"
      height="700"
      :data="tableData"
      remote-sort
      @sort-change="sortList"
    >
      <template v-for="item in columnList">
        <vxe-table-column>
          <vxe-table-column :field="item.field" :title="item.fieldName" width="180" />
          <template v-slot:header="{ column }">
            <el-input v-model="listQuery.name" :placeholder="item.fieldName" clearable />
          </template>
        </vxe-table-column>
      </template>
    </vxe-table>
    <vxe-pager
      :loading="loading"
      :current-page.sync="listQuery.pageNum"
      :page-size.sync="listQuery.pageSize"
      :total="listQuery.total"
      :layouts="['PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump', 'Sizes', 'FullJump', 'Total']"
      @page-change="handlePageChange"
    />
  </div>
</template>
<script>
import Vue from "vue";
import "xe-utils";
import VXETable from "vxe-table";
import "vxe-table/lib/index.css";
import XEUtils from "xe-utils";
import VXEUtils from "vxe-utils";
Vue.use(VXETable, VXEUtils, XEUtils, { mounts: ["cookie"] });
import request from "@/utils/request";
export default {
  name: "diyReport",
  components: {},
  data() {
    return {
      loading: false,
      columnList: [],
      tableData: [],
      listQuery: {
        code: "",
        branchCode: "",
        reportCode: "",
        gmtCreatedStart: "",
        gmtCreatedEnd: "",
        pageNum: 1,
        pageSize: 10,
        sortField: "",
        sortType: "",
        total: 0
      }
    };
  },
  created() {
    this.listQuery.reportCode = this.$route.query.code;
    this.findColumnList();
  },
  methods: {
    //查询自定义列表
    findColumnList() {
      this.loading = true;
      this.listQuery.reportCode = this.$route.query.code;
      request({
        url: "/ntocc-tms-api/diyReportField",
        method: "get",
        params: this.listQuery
      }).then(response => {
        this.columnList = response.data.records;
        this.findList();
      });
    },
    findList() {
      this.loading = true;
      request({
        url: "/ntocc-tms-api/diyReport/selectReport",
        method: "get",
        params: this.listQuery
      }).then(response => {
        this.tableData = response.data.records;
        this.listQuery.total = response.data.total;
        this.loading = false;
      });
    },
    // 排序
    sortList({ column, property, order }) {
      if (order) {
        this.listQuery.sortField = property;
        this.listQuery.sortType = order;
      } else {
        this.listQuery.sortField = "";
      }
      this.findList();
    },
    // 分页handle
    handlePageChange({ currentPage, pageSize }) {
      this.listQuery.pageNum = currentPage;
      this.listQuery.pageSize = pageSize;
      this.findList();
    }
  }
};
</script>

<style>
.vxe-table .vxe-body--column:not(.col--ellipsis),
.vxe-table .vxe-footer--column:not(.col--ellipsis),
.vxe-table .vxe-header--column:not(.col--ellipsis) {
  padding: 6px 0;
}
.vxe-toolbar {
  padding: 0 0 10px 0;
}
</style>
